<#include "../public/header.html">
    <div id="editdlg_windows"></div>
    <div id="p" class="easyui-panel" title="学生信息" style="width:100%;height:550px;">
        <form id="student_form" >
            <input type="hidden" id="id" name="id"/>
            <table class="tableForm tableCss">
                <tr>
                    <td colspan="3" style="text-align: center;">
                        <input class="easyui-searchbox" id="s_cid" data-options="prompt:'输入身份证',searcher:doSearch" style="width:400px"/>
                        <a class="easyui-linkbutton" href="javascript:getcardinfo();" >读取身份证信息</a>
                    </td>
                </tr>
                <tr >
                    <th style="width:33%;text-align: center">
                        身份证头相
                    </th>
                    <th style="width:33%;text-align: center">
                        现场取照
                    </th>
                    <th style="width:34%;text-align: center">
                        实时拍摄
                    </th>
                </tr>
                <tr>
                    <td>
                        <img src="" id="id_card_pic" name="id_card_pic">
                    </td>
                    <td>
                        <img src="" id="student_pic">
                    </td>
                    <td>
                        <div id="webcam" style="float: left;"></div>
                        <div  style="float: right;margin-top: 150px;" >
                            <a class="easyui-linkbutton" href="javascript:take_pic();" data-options="iconCls:'icon-save'">拍摄</a>
                        </div>
                        <div  style="float: right;margin-top: 10px;" >
                            <a class="easyui-linkbutton" onclick="import_student_pic()" data-options="iconCls:'icon-upload'">上传</a>
                        </div>
                    </td>
                </tr>
            </table>
            <table class="tableForm tableCss">
                <tr>
                    <th style="width: 150px;">学校：</th>
                    <td>
                        <input class="easyui-combotree" style="width:100%" name="dep_id" id="dep_id" value="${(po.dep_id!)!}" data-options="url:'admin/department/combotree',method:'get',required:true,onselect:on_change">
                    </td>
                    <th style="width: 150px;">班级：</th>
                    <td>
                        <input class="easyui-combobox"  style="width:100%" name="class_id" id="class_id" value="${(po.class_id!)!}" data-options="url:'admin/class/load_class_combobox?dep_id=${(po.dep_id!)!}',valueField:'id',textField:'class_name',required:true">
                    </td>
                    <th>学生名称：</th>
                    <td>
                        <input class="easyui-textbox"  style="width:100%" type="text"  id="student_name" name="student_name" value="${(po.student_name!)!}" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <th>社保卡号：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" type="text" id="student_sb_cart" name="student_sb_cart" value="${(po.student_sb_cart!)!}">
                    </td>
                    <th>社保卡发放地：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" type="text" id="student_sb_ffd" name="student_sb_ffd" value="${(po.student_sb_ffd!)!}">
                    </td>
                    <th>身份证号：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" type="text" name="student_id_cart" id="student_id_cart" value="${(po.student_id_cart!)!}" >
                    </td>
                </tr>
                <tr>
                    <th>性别：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_sex" id="student_sex" value="${(po.student_sex!)!}" data-options="url:'admin/student/sys_pa_code?table=common&field=sex',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>出生日期：</th>
                    <td>
                        <input class="easyui-datebox" style="width:100%" type="text" name="student_birthday" id="student_birthday" value="${(po.student_birthday!)!}" data-options="formatter:myformatter,parser:myparser" >
                    </td>
                    <th>户籍所在地：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" type="text" name="student_hj_address" value="${(po.student_hj_address!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_hj_address',method:'get',valueField:'id',textField:'name'">
                    </td>
                </tr>
                <tr>
                    <th>户籍地址：</th>
                    <td>
                        <input class="easyui-textbox"  style="width:100%" type="text"  id="student_hj_address_detail" name="student_hj_address_detail" value="${(po.student_hj_address_detail!)!}">
                    </td>
                    <th>户口性质：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_hk_type" id="student_hk_type" value="${(po.student_hk_type!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_hk_type',method:'get',valueField:'id',textField:'name'" >
                    </td>
                    <th>婚姻状态：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_is_marray" id="student_is_marray" value="${(po.student_is_marray!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_is_marray',method:'get',valueField:'id',textField:'name'">
                    </td>
                </tr>
                <tr>
                    <th>民簇：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_nationality" id="student_nationality" value="${(po.student_nationality!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_nationality',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>政治面貌：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_political" id="student_political" value="${(po.student_political!)!}"  data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_political',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>所在单位：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="at_company" id="at_company" value="${(po.at_company!)!}">
                    </td>
                </tr>
                <tr>
                    <th>人员类型：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_type" id="student_type" value="${(po.student_type!)!}"   data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_type',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>鉴定人员类别：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="app_user_type" id="app_user_type" value="${(po.app_user_type!)!}"  data-options="url:'admin/student/sys_pa_code?table=bk_student&field=app_user_type',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>国家职业资格等级：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="national_rank" id="national_rank" value="${(po.national_rank!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=national_rank',method:'get',valueField:'id',textField:'name'">
                    </td>
                </tr>
                <tr>
                    <th>上一级职业资格级别：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="up_national_rank" id="up_national_rank" value="${(po.up_national_rank!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=up_national_rank',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>是否免考理论：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="is_not_testing_theory" id="is_not_testing_theory" value="${(po.is_not_testing_theory!)!}" data-options="url:'admin/student/sys_pa_code?table=common&field=boolean',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>文化程度：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_cultural" id="student_cultural" value="${(po.student_cultural!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_cultural',method:'get',valueField:'id',textField:'name'">
                    </td>
                </tr>
                <tr>
                    <th>最高学历专业：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_high_school_record" id="student_high_school_record" value="${(po.student_high_school_record!)!}">
                    </td>
                    <th>职称：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_title" id="student_title" value="${(po.student_title!)!}">
                    </td>
                    <th>职务：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_duty" id="student_duty" value="${(po.student_duty!)!}">
                    </td>
                </tr>
                <tr>
                    <th>职业年限：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_age_limit" id="student_age_limit" value="${(po.student_age_limit!)!}">
                    </td>
                    <th>专业技术职务级别：</th>
                    <td>
                        <input class="easyui-combobox" style="width:100%" name="student_duty_rank" id="student_duty_rank" value="${(po.student_duty_rank!)!}" data-options="url:'admin/student/sys_pa_code?table=bk_student&field=student_duty_rank',method:'get',valueField:'id',textField:'name'">
                    </td>
                    <th>工龄：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_work_age" id="student_work_age" value="${(po.student_work_age!)!}" >
                    </td>
                </tr>
                <tr>
                    <th>电子邮箱：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_email" id="student_email" value="${(po.student_email!)!}" >
                    </td>
                    <th>联系地址：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_address" id="student_address" value="${(po.student_address!)!}">
                    </td>
                    <th>联系电话：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_tel_phone" id="student_tel_phone" value="${(po.student_tel_phone!)!}">
                    </td>
                </tr>
                <tr>
                    <th>基础信息1：</th>
                    <td>
                        <input class="easyui-textbox" style="width:100%" name="student_memo_1" id="student_memo_1" value="${(po.student_memo_1!)!}">
                    </td>
                    <th>基础信息2：</th>
                    <td colspan="3">
                        <input class="easyui-textbox" style="width:100%" name="student_memo_2" id="student_memo_2" value="${(po.student_memo_2!)!}">
                    </td>
                </tr>
            </table>
        </form>
    </div>


    <script src="public/js/jquery.webcam.min.js"></script>
    <script type="text/javascript">

        var image = new Array();
        var pos = 0;
        var w = 320;
        var h= 240;

        $(document).ready(function(){
            $("#webcam").webcam({
                width: 320,
                height: 240,
                mode: "callback",
                swffile: "public/js/jscam_canvas_only.swf", // canvas only doesn't implement a jpeg encoder, so the file is much smaller

                onTick: function(remain) {
                    alert("tick.....");
                },

                onSave: function(data) {

                    var id =  $("#id").val();
                    image.push(data);
                    pos += 4 * w;
                    if (pos == 4 * w * h) {
                        $.ajax({type:"post",
                            url:"admin/student/take_pic",
                            data:{id:id,w: w, h: h , pix:image.join('|')},
                            dataType:"JSON",
                            success:function (data) {
//                                var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                if(data.success==1){
                                    $("#student_pic").attr("src",data.obj);
                                    $("#student_pic").show();
                                }else{
                                    $("#student_pic").hide();
                                }
                                pos = 0;
                                image = new Array();
                                $.messager.progress('close');

                            }});
                    }

                },

                onCapture: function () {
                    webcam.save();

                    // Show a flash for example
                },

                debug: function (type, string) {
                    // Write debug information to console.log() or a div, ...
                },

                onLoad: function () {

                }
            });


        });

        function take_pic(){
            var id =  $("#id").val();
            if(id == "" || id==null){
                $.messager.show({
                    title:'提醒',
                    msg:'请先加载学生信息',
                    showType:'fade',
                    style:{
                        right:'',
                        bottom:''
                    }
                });
                return;
            }
            $.messager.progress({
                msg:'处理中.....'
            });
            webcam.capture();
        }
        //身份证信息
        function getcardinfo() {
		   clearForm();
		   var ret = CVR_IDCard.ReadCard();
		   if (ret == "0"){
		      fillForm();
		      return;
		   } 
		
		   alert("读卡错误,错误原因:" + ret);
		}
		
		function clearForm() {
		  $("#student_name").textbox('setValue','');
		  $("#student_sex").textbox('setValue','');
		  $("#student_nationality").textbox('setValue','');
		  $("#student_birthday").datebox('setValue','');
		  $("#student_hj_address").textbox('setValue','');
		  $("#student_id_cart").textbox('setValue','');
		  //easyui-datebox
		  $("#student_hj_address_detail").textbox('setValue','');
		  document.all['id_card_pic'].value = ''; 
		}
		function fillForm() {   
		  var pName=CVR_IDCard.Name; 
		  var pSex=CVR_IDCard.Sex;
		  var pNation=CVR_IDCard.Nation;
		  var pBorn=CVR_IDCard.Born;
		  var pAddress=CVR_IDCard.Address;
		  var pCardNo=CVR_IDCard.CardNo;
		  var pPolice=CVR_IDCard.IssuedAt;
		  var pActivityLFrom=CVR_IDCard.EffectedDate; 
		  var pActivityLTo=CVR_IDCard.ExpiredDate; 
		  var pDeviceNo=CVR_IDCard.CardReaderId;
		  var pPhotoBuffer=CVR_IDCard.Picture;  
		  
		  var y = pBorn.substr(0,4);
		  var m = pBorn.substr(4,2);
		  var r = pBorn.substr(6,2);
		  pBorn = y+"-"+m+"-"+r;
		  //getcardinfo
		  $("#student_name").textbox('setValue',pName);
		  $("#student_sex").textbox('setValue',pSex==1?"男":"女");
		  $("#student_nationality").textbox('setValue',pNation);
		  $("#student_birthday").datebox('setValue',pBorn);
		  $("#student_hj_address").textbox('setValue',pPolice);
		  $("#student_id_cart").textbox('setValue',pCardNo);
		  $("#s_cid").searchbox('setValue',pCardNo);
		  $("#student_hj_address_detail").textbox('setValue',pAddress);
		  document.all['id_card_pic'].src = 'data:image/jpeg;base64,' + pPhotoBuffer; 
		  doSearch(pCardNo);
		}

        function doSearch(value){
            $('#student_form').form('clear');
            $.ajax({
                type:"post",
                url:"admin/student/load_form_student",
                data:{id_card:value},
                dataType:"json",
                success:function(data){
                    if(data.success==1){
                        $("#student_form").form('load',data.obj);

                        if(data.obj.id_card_pic!== undefined){
                            $("#id_card_pic").attr("src",data.obj.id_card_pic);
                            $("#id_card_pic").show();
                        }else{
                            $("#id_card_pic").hide();
                        }

                        if(data.obj.student_pic!== undefined){
                            $("#student_pic").attr("src",data.obj.student_pic);
                            $("#student_pic").show();
                        }else{
                            $("#student_pic").hide();
                        }
                    }else{
                        $.messager.show({
                            title:'提醒',
                            msg:data.msg,
                            showType:'fade',
                            style:{
                                right:'',
                                bottom:''
                            }
                        });
                    }

                    $("#s_cid").searchbox('setValue',value);
                }
            })
        }
        function on_change(){
            var dep_id = $("#dep_id").combotree("getValue");
            $("#class_id").combobox("reload",'admin/class/load_class_combobox?dep_id='+dep_id);
        }

        function myformatter(date){
            var y = date.getFullYear();
            var m = date.getMonth()+1;
            var d = date.getDate();
            return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
        }
        function myparser(s){
            if (!s) return new Date();
            var ss = (s.split('-'));
            var y = parseInt(ss[0],10);
            var m = parseInt(ss[1],10);
            var d = parseInt(ss[2],10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
                return new Date(y,m-1,d);
            } else {
                return new Date();
            }
        }

        var import_student_pic = function (){

            var id =  $("#id").val();
            if(id == "" || id==null){
                $.messager.show({
                    title:'提醒',
                    msg:'请先加载学生信息',
                    showType:'fade',
                    style:{
                        right:'',
                        bottom:''
                    }
                });
                return;
            }

            $("#editdlg_windows").dialog({
                title: "导入头相",
                iconCls: 'icon-edit',
                width: 400,
                height: 200,
                closed: false,
                cache: false,
                modal: true,
                href: "admin/student/import_pic?id="+id,
                onLoad: function () {
                    $.messager.progress('close');
                },
                buttons: [{
                    text: '取消',
                    iconCls:'icon-cancel',
                    handler: function () {
                        $("#editdlg_windows").dialog("close");
                    }
                },{
                    text: '导入',
                    iconCls: 'icon-back',
                    handler: function(){
                        $('#import_student_pic_Form').form('submit',{
                            url:"admin/student/upload_pic",
                            dataType:"json",
                            onSubmit:function(){
                                return $(this).form('enableValidation').form('validate');
                            },
                            success:function(data){
                                var data = eval('(' + data + ')');  // change the JSON string to javascript object

                                $.messager.alert("提示",data.msg);
                                if(data.success==1){
                                    $('#import_student_pic_Form').form('clear');
                                    $("#editdlg_windows").dialog("close");

                                    doSearch($("#s_cid").searchbox('getValue'));
                                }
                            }
                        });

                    }

                }]
            });
        }
    </script>

    <#include "../public/footer.html">